function lookadmin() {
	$.ajax({
		type: "post",
		url: host + "user/lookadmin",
		async: true,
		datatype: "json",
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				var addhtml = $("#admin").html();;
				Mustache.parse(addhtml);
				result = {
					admin_number: ret['arr'][0]['admin_usernumber'],
					admin_username: ret['arr'][0]['admin_username'],
					admin_lastlogintime: ret['arr'][0]['admin_lastlogintime']
				};

				var html = Mustache.render(addhtml, result);
				$('#body').html(html);
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function lookdepartment() {
	var addhtml = $("#departmentlist").html();;
	Mustache.parse(addhtml);
	var html = Mustache.render(addhtml);
	$('#body').html(html);
	$.ajax({
		type: "post",
		url: host + "Department/lookdepartment",
		async: true,
		data: {
			TOKEN: $.cookie('TOKEN'),
			USERID: $.cookie('USERID'),
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				for(var i = 0; i < (ret['arr']).length; i++) {
					var addhtml = $("#departmentbody").html();;
					Mustache.parse(addhtml);
					var result = {
						department_name: ret['arr'][i]['department_name'],
						department_data: JSON.stringify(ret['arr'][i])
					};
					var html = Mustache.render(addhtml, result);
					$('#departmentbodyhtml').html($('#departmentbodyhtml').html() + html);
				}
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function lookuser() {
	var addhtml = $("#lookuserhead").html();;
	Mustache.parse(addhtml);
	var html = Mustache.render(addhtml);
	$('#body').html(html);
	$.ajax({
		type: "post",
		url: host + "user/lookuser",
		async: true,
		datatype: "json",
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				for(var i = 0; i < (ret['arr']).length; i++) {
					var addhtml = $("#lookuserbody").html();;
					Mustache.parse(addhtml);
					result = {
						user_usernumber: ret['arr'][i]['user_usernumber'],
						user_username: ret['arr'][i]['user_username'],
						user_department: ret['arr'][i]['user_department'],
						user_time: ret['arr'][i]['user_lastlogintime'],
						user_data: JSON.stringify(ret['arr'][i])
					};
					var html = Mustache.render(addhtml, result);
					$('#lookuserbodyhtml').html($('#lookuserbodyhtml').html() + html);
				}
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function makeuser() {
	$.ajax({
		type: "post",
		url: host + "User/makeuser",
		async: true,
		data: {
			user_usernumber: $("#addusernumber").val(),
			user_username: $("#addusername").val(),
			user_password: $("#addpassword").val(),
			user_department: $("#adddepartment").val(),
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				lookuser();
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function makedepartment() {
	var name = prompt("请输入部门名称", "")
	if(name != null && name != "") {
		$.ajax({
			type: "post",
			url: host + "Department/makedepartment",
			async: true,
			data: {
				department_name: name,
				TOKEN: $.cookie('TOKEN'),
				USERID: $.cookie('USERID'),
			},
			success: function(ret) {
				ret = eval('(' + ret + ')');
				if(ret['status'] == 1) {
					lookdepartment();
				} else {
					alert(ret['msg']);
				}
			}
		});
	}
}

function openadduser() {
	var addhtml = $("#adduser").html();;
	Mustache.parse(addhtml);
	var html = Mustache.render(addhtml);
	$('#body').html(html);
	var str = "";
	$.ajax({
		type: "post",
		url: host + "department/lookdepartment",
		async: true,
		datatype: "json",
		data: {
			TOKEN: $.cookie('TOKEN'),
			USERID: $.cookie('USERID'),
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				for(var i = 0; i < (ret['arr']).length; i++) {
					str += "<option value=" + ret['arr'][i]['department_name'] + ">" + ret['arr'][i]['department_name'] + "</option>";
				}
				$("#adddepartment").html(str);
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function opendetailuser(data) {
	data = eval('(' + data + ')');
	var addhtml = $("#lookdetailuser").html();;
	Mustache.parse(addhtml);
	var result = {
		usernumber: data['user_usernumber'],
		username: data['user_username'],
		userpassword: data['user_password'],
		userdepartment: data['user_department'],
		userdata: JSON.stringify(data)
	};
	var html = Mustache.render(addhtml, result);
	$('#body').html(html);
}

function opentoexcel() {
	openlookfile();
	window.open(host + "User/toexcel");
}

function opendetailfile(data) {
	data = eval('(' + data + ')');
	$('#body').html("");
	var addhtml = $("#detailfile").html();;
	Mustache.parse(addhtml);
	result = {
		file_filenumber: data['file_filenumber'],
		file_filername: data['file_filername'],
		file_phonenumber: data['file_phonenumber'],
		file_money: data['file_money'],
		file_detail: data['file_detail'],
		file_pic: data['file_pic'],
		file_data: JSON.stringify(data),
		file_department: data['file_department'],
		file_fileclass: data['file_fileclass']
	};
	var html = Mustache.render(addhtml, result);
	$('#body').html(html);
	if(data['file_isnone'] == "0") {
		var addhtml = $("#defaultophtml").html();
		result = {
			file_data: JSON.stringify(data),
		};
		Mustache.parse(addhtml);
		var html = Mustache.render(addhtml, result);
		$('#op').html(html);
		//fs
		var isqianshou, iszhuangtai;
		if(data['file_isback'] == 0) {
			isqianshou = "已签收";
		} else {
			if(data['file_isback'] == 2) {
				isqianshou = "待审核";
			} else {
				isqianshou = "已退回";
			}
		}

		if(data['file_issignature'] == 0) {
			iszhuangtai = "未签批";
		} else {
			if(data['file_isfinish'] == 1) {
				iszhuangtai = "已领取";
			} else {
				iszhuangtai = "已签批";
			}
		}
		var addhtml = $("#defaultfilestatus").html();
		result = {
			isqianshou: isqianshou,
			iszhuangtai: iszhuangtai,
			file_id: data['file_id']
		};
		Mustache.parse(addhtml);
		var html = Mustache.render(addhtml, result);
		$('#fs').html(html);
		if(data['file_isback'] != 0) {
			$("#wenjianstatus_k").addClass("hide");
		}
	} else {
		var addhtml = $("#noneophtml").html();;
		Mustache.parse(addhtml);
		var html = Mustache.render(addhtml);
		$('#op').html(html);
		//fs
		var isqianshou, iszhuangtai;
		if(data['file_isback'] == 0) {
			isqianshou = "已签收";
		} else {
			if(data['file_isback'] == 2) {
				isqianshou = "待审核";
			} else {
				isqianshou = "已退回";
			}
		}

		if(data['file_issignature'] == 0) {
			iszhuangtai = "未签批";
		} else {
			if(data['file_isfinish'] == 1) {
				iszhuangtai = "已领取";
			} else {
				iszhuangtai = "已签批";
			}
		}
		var addhtml = $("#nonefilestatus").html();
		result = {
			isqianshou: isqianshou,
			iszhuangtai: iszhuangtai,
			file_id: data['file_id']
		};
		Mustache.parse(addhtml);
		var html = Mustache.render(addhtml, result);
		$('#fs').html(html);
		if(data['file_isback'] != 0) {
			$("#wenjianstatus_k").addClass("hide");
		}
	}
	$("#fileBC").barcode(data['file_filenumber'], "code128");
}

function opennonefile(data, clicktype) {
	data = eval('(' + data + ')');
	var r = confirm("确定此文件已经挂失？挂失后不能撤销");
	if(r == true) {
		if(data['file_isnone'] == 1) {
			alert("此文件已经挂失");
			return;
		}
		$.ajax({
			type: "post",
			url: host + "file/nonethefile",
			data: {
				TOKEN: $.cookie('TOKEN'),
				USERID: $.cookie('USERID'),
				file_id: data['file_id']
			},
			async: true,
			datatype: "json",
			success: function(ret) {
				ret = eval('(' + ret + ')');
				if(ret['status'] == 1) {
					if(clicktype == "all") {
						openlookfile();
					} else {
						openlookfile();
					}
				} else {
					alert(ret['msg']);
				}
			}
		});
	}
}

function openlookfile() {
	$('#body').html("");
	var addhtml = $("#lookfile").html();
	Mustache.parse(addhtml);
	var html = Mustache.render(addhtml);
	$('#body').html(html);
	$.ajax({
		type: "post",
		url: host + "file/lookfile",
		data: {
			TOKEN: $.cookie('TOKEN'),
			USERID: $.cookie('USERID'),
		},
		async: true,
		datatype: "json",
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				$("#lookfilebody_html").html("");
				for(var i = 0; i < (ret['arr']).length; i++) {
					var filestatus = "已登记";
					var cssclass = "active";
					if(ret['arr'][i]['file_isback'] == 0) {
						if(ret['arr'][i]['file_issignature'] == 1) {
							filestatus = "已签批";
							cssclass = "warning";
							if(ret['arr'][i]['file_isfinish'] == 1) {
								filestatus = "已领取";
								cssclass = "success";
							}
						}
					} else {
						if(ret['arr'][i]['file_isback'] == 2) {
							filestatus = "待审核";
							cssclass = "info";
						} else {
							filestatus = "已退回";
							cssclass = "danger";
						}

					}
					var addhtml = $("#lookfilebody").html();
					Mustache.parse(addhtml);

					result = {
						file_cssclass: cssclass,
						file_filenumber: ret['arr'][i]['file_filenumber'],
						file_filername: ret['arr'][i]['file_filername'],
						file_phonenumber: ret['arr'][i]['file_phonenumber'],
						file_department: ret['arr'][i]['file_department'],
						file_fileclass: ret['arr'][i]['file_fileclass'],
						file_money: ret['arr'][i]['file_money'],
						file_detail: ret['arr'][i]['file_detail'],
						file_data: JSON.stringify(ret['arr'][i]),
						file_status: filestatus
					}
					var html = Mustache.render(addhtml, result);
					$('#lookfilebody_html').html($('#lookfilebody_html').html() + html);
				}
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function openmorefile(fnc) {
	$('#body').html("");
	var addhtml = $("#moreinfofile").html();;
	Mustache.parse(addhtml);
	var html = Mustache.render(addhtml);
	$('#body').html(html);
	$.ajax({
		type: "post",
		url: host + "file/" + fnc,
		data: {
			TOKEN: $.cookie('TOKEN'),
			USERID: $.cookie('USERID')
		},
		async: true,
		datatype: "json",
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				$('#moreinfofile_html').html("");
				for(var i = 0; i < (ret['arr']).length; i++) {
					var addhtml = $("#moreinfofilebody").html();;
					Mustache.parse(addhtml);
					result = {
						file_pic: ret['arr'][i]['file_pic'],
						file_filenumber: ret['arr'][i]['file_filenumber'],
						file_filername: ret['arr'][i]['file_filername'],
						file_data: JSON.stringify(ret['arr'][i])
					};
					var html = Mustache.render(addhtml, result);
					$('#moreinfofile_html').html($('#moreinfofile_html').html() + html);
				}
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function openoplist() {
	var addhtml = $("#oplistthead").html();;
	Mustache.parse(addhtml);
	var html = Mustache.render(addhtml);
	$('#body').html(html);

	$.ajax({
		type: "post",
		url: host + "User/lookop",
		async: true,
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				for(var i = 0; i < (ret['arr']).length; i++) {
					var addhtml = $("#oplisttbody").html();;
					Mustache.parse(addhtml);
					var result = {
						op_usernumber: ret['arr'][i]['op_usernumber'],
						op_username: ret['arr'][i]['op_username'],
						op_department: ret['arr'][i]['op_department'],
						op_object: ret['arr'][i]['op_object'],
						op_content: ret['arr'][i]['op_content'],
						op_time: ret['arr'][i]['op_time']
					}
					var html = Mustache.render(addhtml, result);
					$('#oplisttbodyhtml').html($('#oplisttbodyhtml').html() + html);
				}
			} else {
				alert(ret['msg']);
			}
		}
	});

}

function openqianshou(file_id) {
	$.ajax({
		type: "post",
		url: host + "File/changeqianshou",
		async: true,
		data: {
			TOKEN: $.cookie('TOKEN'),
			USERID: $.cookie('USERID'),
			file_id: file_id,
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				$("#qianshoustatus").html("已签收");
				$("#qianshouop").addClass("hide");
				$("#wenjianstatus_k").removeClass("hide");
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function opentuihui(file_id) {
	$.ajax({
		type: "post",
		url: host + "File/changetuihui",
		async: true,
		data: {
			TOKEN: $.cookie('TOKEN'),
			USERID: $.cookie('USERID'),
			file_id: file_id,
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				$("#qianshoustatus").html("已退回");
				$("#qianshouop").addClass("hide");
				$("#wenjianstatus_k").addClass("hide");
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function openwenjianstatus(file_id, type) {
	$.ajax({
		type: "post",
		url: host + "File/changfilestatus",
		async: true,
		data: {
			TOKEN: $.cookie('TOKEN'),
			USERID: $.cookie('USERID'),
			file_id: file_id,
			type: type,
			op_usernumber: $.cookie('USERID')
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				$("#wenjianstatus").html(type);
				$("#wenjianop").addClass("hide");
			} else {
				alert(ret['msg']);
			}
		}
	});

}

function deleteuser(data) {
	data = eval('(' + data + ')');
	$.ajax({
		type: "post",
		url: host + "User/deluser",
		async: true,
		data: {
			user_id: data['user_id']
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				lookuser();
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function changeuser(data) {
	data = eval('(' + data + ')');
	$.ajax({
		type: "post",
		url: host + "User/saveuser",
		async: true,
		data: {
			user_id: data['user_id'],
			user_usernumber: $('#usernumber').val(),
			user_username: $('#username').val(),
			user_password: $('#userpassword').val(),
			user_department: $('#userdeparment').val()
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				lookuser();
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function deldepartment(data) {
	data = eval('(' + data + ')');
	$.ajax({
		type: "post",
		url: host + "Department/deldepartment",
		async: true,
		data: {
			TOKEN: $.cookie('TOKEN'),
			USERID: $.cookie('USERID'),
			department_id: data['department_id']
		},
		success: function(ret) {
			ret = eval('(' + ret + ')');
			if(ret['status'] == 1) {
				lookdepartment();
			} else {
				alert(ret['msg']);
			}
		}
	});
}

function openop(type) {
	$("#" + type).removeClass("hide");
}